<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/11/13
  Time: 19:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>查看所有管理员</title>
    <script src="/WebContent/JQuery/jquery-3.4.1.js" type="text/javascript"></script>
    <style type="text/css" rel="stylesheet">
        body{
            font-family: "楷体";
            font-size: 16px;
        }
        .all{
            width: 1100px;
            max-height: 450px;
            overflow: auto;
            border: 2px solid rgb(97,166,0);
            margin: 0 auto;
            padding: 50px 30px;
            box-sizing: border-box;
        }
        .yheader{
            font-size: 18px;
            font-weight: 600;
            color: rgb(97,166,0);
            margin-bottom: 10px;
        }
        table{
            width: 600px;
            margin: 0 auto;
        }
        td{
            text-align: center;
        }
        a{
            color: rgb(97,166,0);
            text-decoration: none;
            font-family: "楷体";
            font-weight: 600;
        }
        a:hover{
            color: red;
        }
    </style>
</head>
<body>
    <article class="all">
        <div class="yheader">当前位置&nbsp;&gt;&gt;&nbsp;查看所有管理员</div>
        <table border="1">
            <tr>
                <th>编号</th>
                <th>用户名</th>
                <th>邮箱地址</th>
                <th>注册时间</th>
                <th>类型</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${requestScope.admins}" var="admin" varStatus="status">
                <tr>
                    <td style="display: none" class="id">${admin.adminId}</td>
                    <td>${status.count}</td>
                    <td>${admin.adminUsername}</td>
                    <td>${admin.adminEmail}</td>
                    <td>${admin.adminRegisterTime}</td>
                    <td class="type">${admin.adminRoleType==1?"超管":"普管"}</td>
                    <td><a href="javascript:void(0);" class="del">卸任</a></td>
                </tr>
            </c:forEach>
        </table>
    </article>
    <script>
        $(document).ready(function () {
             $(".del").click(function () {
                 if(confirm("确定取消管理权限吗？")){
                     var text = $.trim($(this).parent().siblings(".type").text());
                     var id = $.trim($(this).parent().siblings(".id").text());
                     if(id == "1"){
                         alert("您的权限不足！");
                     }else{
                         $.ajax({
                             url:"/SuperAdminServlet?type=delete",
                             type:"get",
                             data:{"id":id},
                             dataType:"text",
                             async:true,
                             success:function (data) {
                                 if(data == "1"){
                                     alert("删除成功！");
                                     window.location.reload();
                                 }else{
                                     alert("删除失败，请联系后重试！");
                                 }
                             },
                             error:function (error) {
                                 alert("操作失败！");

                             }
                         })
                     }
                 }else
                     return false;

             })
        })
    </script>
</body>
</html>
